package thread;

public class Demo14 {
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 3; i++) {
                System.out.println("这是线程t1");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("线程t1结束!");
        });

        Thread t2 = new Thread(() -> {
            for (int i = 0; i < 4   ; i++) {
                System.out.println("这是线程t2");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("线程t2结束!");
        });

        t1.start();
        t2.start();
        System.out.println("主线程开始等待");
        t2.join();
        t1.join();
        System.out.println("主线程结束等待");
    }
}
